﻿//Copyright (C) <2013>  <jonathan cleeve norton> All Rights Reserved 
//Contact jon.norton@fin-plus.co.uk website <http://www.fin-plus.co.uk/>
using FinPlusInterfaces;

namespace FinPlusBaseCore
{
    public class PPod : IPPod
    {
        public bool CanRead { get; private set; }
        public bool CanWrite { get; private set; }
        public bool Overwrite { get; private set; }

        //construct
        public PPod(bool canRead, bool canWrite):this(canRead, canWrite, false){}

        public PPod(bool canRead, bool canWrite, bool ovewrite)
        {
            CanRead = canRead;
            CanWrite = canRead ? canWrite : false;
            Overwrite = ovewrite;
        }

        //public
        public IPPod Add(IPPod permission)
        {
            if (Overwrite)
                return this;
            return new PPod(CanRead && permission.CanRead ? true : false, CanWrite && permission.CanWrite ? true : false, permission.Overwrite);
        }

        public override string ToString()
        {
            return string.Format("CanRead {0} CanWrite {1}", CanRead.ToString(), CanWrite.ToString());
        }
    }
}

